SG Window | |
DoModeless Method |
See Also Overview Properties Methods Events Constants Error Codes How To... FAQ |
Opens modeless dialog box.
object.DoModeless resFile As String, dlgTemplate, left As Long, top As Long, Optional initParam As Long = 0
Part | Description |
object | The object is expression that evaluates to Window object |
resFile | String that specifies where is the dialog template resource located. This is usually name of the file containing dialog resource. |
dlgTemplate | Name or identifier of the dialog template. Can be string that specifies the name of the dialog box template (i.e. "DLG_EMPTY") or an integer value that specifies the resource identifier of the dialog box template. |
left, top | Dialog's initial top-left corner coordinate. In screen pixel coordinates. |
initParam | Optional. Specifies the value to pass to the dialog box in the lParam parameter of the WM_INITDIALOG message. |
DoModeless method creates modeless dialog box from a specified dialog box template resource and immediately returns control to the caller.
Resource template is located in the file specified by resFile parameter:
resFile Value | Description |
"" | Empty string. Dialog box template is located in the SGWINDOW.DLL module. |
"file_spec" | Dialog box template is located in the file 'file_spec" |
SGWINDOW.DLL module contains an 'empty' dialog box template. This template (DLG_EMPTY) can be used to create custom dialog boxes. Following code shows how to create modeless dialog box using DLG_EMPTY template:
option explicit ' Messages and styles const wm_CLOSE = &H0010& const wm_INITDIALOG = &H0110& const wm_COMMAND = &H0111& const PBM_SETRANGE = &H0401& const PBM_SETPOS = &H0402& const PBS_SMOOTH = &H0001& const ws_CHILD = &H40000000 const ws_VISIBLE = &H10000000 const ws_TABSTOP = &H00010000 const sMsg = "VBScript is working " ' Global declarations Dim g, dlg, wProgress, wStatic, i, rc, bCanceled Set g = WScript.CreateObject("SGWindow.Globals") Set dlg = WScript.CreateObject("SGWindow.Window", "dlg_") Set wProgress = WScript.CreateObject("SGWindow.Window") Set wStatic = WScript.CreateObject("SGWindow.Window") ' Show dialog ' Note that empty string as a resource module instructs ' SGWindow to use it's internal dialog resources. dlg.DoModeless "", "DLG_EMPTY", 100, 100 ' Do something bCanceled = false for i = 0 to 1000 step 10 ' Use Sleep method to give dialog box a chance to handle ' it's messages. Note that second parameter (true) ' instructs SGWindow to dispatch messages and events during ' sleep period. g.Sleep 50, true ' Update progress bar wProgress.SendMessage PBM_SETPOS, i, 0 wStatic.Text = sMsg & CStr(i) & "/1000" if bCanceled Then MsgBox "Canceling at " & CStr(i) & "/1000" Exit For end if next ' Release objects Wscript.DisconnectObject dlg dlg.Destroy Set dlg = Nothing Set wProgress = Nothing Set wStatic = Nothing Set g = Nothing WScript.Quit '-------------------------------------------------------------------------- ' Dialog box window procedure '-------------------------------------------------------------------------- Sub dlg_Message(msg, wParam, lParam, result) result = 0 select case msg case wm_INITDIALOG ' Initialize and position dialog dlg.Text = "WSH Modeless Progress Bar" dlg.SetPosition 300, 300, 400, 150 ' Create progress bar wProgress.Create "msctls_progress32", "", WS_CHILD + WS_VISIBLE + PBS_SMOOTH, 0, _ 20, 20, dlg.Width-45, 25, dlg.hWnd, 100 wProgress.SendMessage PBM_SETRANGE, 0, g.MakeLong(0, 1000) ' Create label wStatic.Create "STATIC", sMsg, WS_CHILD + WS_VISIBLE, 0, _ 20, 50, 255, 25, dlg.hWnd, 101 ' Create CANCEL button Dim w Set w = WScript.CreateObject("SGWindow.Window") w.Create "BUTTON", "Cancel", WS_CHILD + WS_VISIBLE + WS_TABSTOP, 0, _ dlg.Width/2-50, dlg.Height-60, 100, 30, dlg.hWnd, 2 w.hFont = dlg.hFont w.SetFocus case wm_CLOSE bCanceled = True case wm_COMMAND Dim bHandled bHandled = OnCommand(g.HighWord(wParam), g.LowWord(wParam), lParam) if Not bHandled Then result = dlg.CallWindowProc(msg, wParam, lParam) end if case else result = dlg.CallWindowProc(msg, wParam, lParam) end select End Sub '-------------------------------------------------------------------------- ' Handle dialog WM_COMMAND messages '-------------------------------------------------------------------------- Private Function OnCommand(notifyCode, id, hwnd) OnCommand = false select case id case 2 ' CANCEL bCanceled = True OnCommand = True end select End Function